import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:theme_page/library/model/RouteModel.dart';

class PlatformApi {
  static const NetApi = "NetApi";
  static const RouteApi = "RouteApi";

  static const HttpMethodGet = "Get";
  static const HttpMethodPost = "Post";

  static late MethodChannel sChannel = MethodChannel("PlatformApi");

  static Future<String?> netApi(String path, [Map<String, String> p = const {}, String method = HttpMethodGet]) {
    Map<String,dynamic> map = Map();
    map["method"] = method;
    map["path"] = path;
    map["param"] = p;
    return sChannel.invokeMethod<String>(NetApi, jsonEncode(map));
  }

  static Future<String?> routeApi(Map<String,dynamic>? p) async{
    try {
      if(p == null){
        return null;
      }
      await sChannel.invokeMethod<String>(RouteApi, jsonEncode(p));
    } catch (e) {
      print(e);
    }
  }

}
